/**
 * 
 */
package com.and.xmppsdk.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.and.xmppsdk.R;
import com.and.xmppsdk.util.AssistHeper;

/**
 * @author hljdrl@gmail.com
 * 设置页面
 *
 */
public final class SettingsFragment extends Fragment implements OnCheckedChangeListener{
	
	private View rootView;
	private ToggleButton mEarPhoneTB;
	private ToggleButton mAudioTB;
	private ToggleButton mVibratorTB;
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		rootView = getView();
		setupView();
	}

	public void setupView() {
		mEarPhoneTB = (ToggleButton) rootView.findViewById(R.id.earphone_ToggleButton);
		mAudioTB = (ToggleButton) rootView.findViewById(R.id.audio_ToggleButton);
		mVibratorTB = (ToggleButton) rootView.findViewById(R.id.vibrator_ToggleButton);
		mEarPhoneTB.setOnCheckedChangeListener(this);
		mAudioTB.setOnCheckedChangeListener(this);
		mVibratorTB.setOnCheckedChangeListener(this);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.root_ft_settings, container, false);
		return view;
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (buttonView.getId() == R.id.earphone_ToggleButton) {
			if (isChecked) {
				AssistHeper.openEarphone(getActivity(), true);
			} else {
				AssistHeper.openEarphone(getActivity(), false);
			}
		} else if (buttonView.getId() == R.id.audio_ToggleButton) {
			if (isChecked) {
				AssistHeper.audio_flag = true;
				AssistHeper.openAudio(getActivity());
			} else {
				AssistHeper.audio_flag = false;
				AssistHeper.closeAudio(getActivity());
			}
		}else {
			if (isChecked) {
				AssistHeper.vibrator_flag = true;
				AssistHeper.openVibrator(getActivity(), true);
			} else {
				AssistHeper.vibrator_flag = false;
			}
		}
	}
}
